<template>
	<view>
		<!-- 用户列表 -->
		<scroll-view class="user-list" scroll-y :show-scrollbar="false">
			<view v-for="(user, index) in userList" :key="user.id" class="user-item"
				:class="{'first-level': user.level === 1}">
				<!-- 一级用户 -->
				<view class="user-info" @click="toggleExpand" :data-user="index">
					<image class="avatar" :src="user.avatar" mode="aspectFill" />
					<view class="info-content">
						<text class="username" :class="{'first-level-name': user.level === 1}">
							{{user.username}}
						</text>
						<!-- <text class="bio">{{user.bio}}</text> -->
					</view>
					<view class="right-content">
						<text class="time">{{user.createtime}}</text>
						<uni-icons v-if="user.level === 1" :type="user.expanded ? 'arrowup' : 'arrowdown'" size="16px"
							color="#999" />
					</view>
				</view>

				<!-- 二级用户列表 -->
				<view v-if="user.expanded == 1" class="second-level-list">
					<view v-for="child in user.children" :key="child.id" class="user-item second-level">
						<view class="user-info">
							<image class="avatar" :src="child.avatar" mode="aspectFill" />
							<view class="info-content">
								<text class="username">{{child.username}}</text>
								<!-- <text class="bio">{{child.bio}}</text> -->
							</view>
							<text class="time">{{child.createtime}}</text>
						</view>
					</view>
				</view>

				<!-- 分割线 -->
				<!-- <view v-if="index < userList.length - 1" class="divider"></view> -->
			</view>
		</scroll-view>
	



	<veiw class="footer">
		<image @click="seeimgs" src="/static/fx.png" mode=""></image>
	</veiw>

	</view>


</template>

<script>
	
	import { mapState } from 'vuex';
	export default {
		data() {
			return {
				userList: [],
				userinfo:[]
			}
		},
		
		onShow() {
			this.getmydowns();
			
			this.getuserinfo();
		},
		methods: {
			async getmydowns(){
					
				var that=this;
				let lists = await this.$api.request('/downs/getmydown', 'POST');
			
				console.log('=========',lists)
			
				that.userList=lists;
				
			},
			async getuserinfo(){
				
				var that=this;
				let user = await this.$api.request('/user/userinfo', 'POST');
							
				console.log('=========',user)
							
				that.userinfo=user;
				
			},
			toggleExpand(ret) {
				console.log(ret);

				var userList = this.userList;

				var index = ret.currentTarget.dataset.user;

				var t = userList[index].expanded;

				userList[index].expanded = !t;

				this.userList = userList;

			},
			seeimgs(){
				var user=this.userinfo;
				
				if	(user.viptime=='未开通会员'){
				
					uni.showToast({
						title:'未开通会员',
						icon:'none'
					})
				
					return false;	
				}
				
				uni.navigateTo({
					url:"/pages/share/image"
				})
			}
		}
	}
</script>

<style>
	
	.footer>image{
		width: 100rpx;
		height: 100rpx;
	}
	.footer{
		position: fixed;
		bottom: 250rpx;
		right: 40rpx;
		z-index: 99;
		width: 100rpx;
		height: 100rpx;
	}
	page {
		height: 100%;
		background-color: #f7f7f7;
	}

	.page-container {
		display: flex;
		flex-direction: column;
		height: 100%;
	}

	.nav-bar {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx 24rpx;
		background-color: #fff;
		border-bottom: 1px solid #f0f0f0;
	}

	.nav-title {
		font-size: 18px;
		font-weight: 500;
		color: #333;
	}

	.nav-placeholder {
		width: 24px;
		height: 24px;
	}

	.user-list {
		flex: 1;
		overflow: auto;
		padding: 0 24rpx;
		background-color: #fff;
	}

	.user-item {
		padding: 24rpx 0;
	}

	.first-level {
		background-color: #fff;
		border-radius: 12rpx;
		margin-top: 20rpx;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
	}

	.user-info {
		display: flex;
		align-items: center;
	}

	.avatar {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		margin-right: 20rpx;
		flex-shrink: 0;
	}

	.info-content {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: center;
		overflow: hidden;
	}

	.username {
		font-size: 16px;
		color: #333;
		margin-bottom: 4rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.first-level-name {
		font-size: 18px;
		font-weight: 500;
	}

	.bio {
		font-size: 12px;
		color: #999;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.right-content {
		display: flex;
		align-items: center;
	}

	.time {
		font-size: 12px;
		color: #999;
		margin-right: 10rpx;
	}

	.second-level-list {
		margin-top: 20rpx;
		padding-left: 100rpx;
	}

	.second-level {
		padding: 16rpx 0;
	}

	.divider {
		height: 1px;
		background-color: #f0f0f0;
		margin: 0 -24rpx;
	}
</style>